//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by Apple on 16/8/4.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewController(childViewController: HomeViewController(), title: "首页", imagename: "tabbar_home");

        addChildViewController(childViewController: MessageViewController(), title: "消息", imagename: "tabbar_message_center");
        addChildViewController(childViewController: DiscoverViewController(), title: "发现", imagename: "tabbar_discover");
         addChildViewController(childViewController: ProfileViewController(), title: "我", imagename: "tabbar_profile");
        
    }

    
    //添加子控件 ， 代码抽取
    private func addChildViewController(childViewController vc: UIViewController , title:String, imagename:String) {
        
        let nav = UINavigationController(rootViewController: vc);
        vc.title = title;
        vc.tabBarItem.image = UIImage(named: imagename);
        
        //方法一！！//选中按钮的图片的颜色要要原始的，文字前景颜色也要一直
        vc.tabBarItem.selectedImage = UIImage(named: imagename+"_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected);
        //方法二！！ 可以直接设置颜色。 !!性能或许会高一点点！
//        tabBar.tintColor = UIColor.orangeColor();
        
        
        addChildViewController(nav);
    }

    

    
    
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
